export default {
  /**
   * 获取get请求的参数
   * @param url
   * @param name
   * @returns {string}
   */
  getUrlParam(url, name) {
    let result = ''
    url.split('?')[1].split('&').forEach(item => {
      if (item.split('=')[0] === name) {
        result = item.split('=')[1]
      }
    })
    return result
  },
  /**
   * 获取get请求的参数Map
   * @param url                 url
   * @returns {Map<any, any>}   参数Map
   */
  getUrlParams(url) {
    let result = new Map()
    const split = url.split('?');
    if (split.length < 2) {
      return result
    }
    split[1].split('&').forEach(item => {
      result.set(item.split('=')[0], item.split('=')[1])
    })
    return result
  },
  /**
   * 获取get请求的参数Map，忽略某些字段
   * @param url                 url
   * @param ignoreField         忽略的字段
   * @returns {Map<any, any>}   参数Map
   */
  getUrlParamsAndIgnoreField(url, ...ignoreField) {
    let allParams = this.getUrlParams(url);
    let filteredParams = new Map();
    allParams.forEach((value, key) => {
      if (!ignoreField.includes(key)) {
        filteredParams.set(key, value);
      }
    });
    return filteredParams;
  },
  /**
   * 获取get请求的参数Map，忽略分页字段
   * @param url                 url
   * @returns {Map<any, any>}   参数Map
   */
  getUrlParamsExcludePageField(url) {
    return this.getUrlParamsAndIgnoreField(url, 'page')
  },
  /**
   * 获取路径参数
   * eg: /systemParam/detail/123456    =>  123456
   * @param url
   * @return {*}    参数
   *
   */
  getPathUrlParams(url) {
    return url.split("/").pop()
  }
}


